//
//  TMDataRequest.h
//  复合发行4.0
//
//  Created by liubowen on 2017/8/30.
//  Copyright © 2017年 Beijing TMYK Technology co.,ltd. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFNetworking.h"
#import "TMAPIConfig.h"
#import "TMAPIParameter.h"

extern NSString *const TMConnectionChanged;

typedef NS_ENUM(NSInteger, TMDataRequestType) {
    TMDataRequestTypeGet,
    TMDataRequestTypePost,
    TMDataRequestTypeDelete,
    TMDataRequestTypePut,
};
/**
 *  请求开始前预处理block
 */
typedef void(^PrepareExecuteBlock) (void);

@interface TMDataRequest : NSObject
+ (TMDataRequest *)defaultRequest;

/**
 *  @brief HTTP请求（GET、POST、DELETE、PUT）
 *
 *  @param urlSting  接口文件地址
 *  @param parameters 接口参数
 *  @param method     RESTFul请求类型
 *  @param prepare    请求前预处理块
 *  @param success    请求成功处理块
 *  @param error      请求数据错误（返回数据status_code不是100）处理块
 *  @param failure    请求失败处理块
 */

- (void)requestWithPath:(NSString *)urlSting
             parameters:(id)parameters
                 method:(NSInteger)method
         prepareExecute:(PrepareExecuteBlock) prepare
                success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                  error:(void (^)(NSInteger errorCode, NSString *errorMessage))error
                failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

/**
 *  @brief HTTP请求（默认GET方式和默认接口文件地址，默认请求前预处理）
 *
 *  @param parameters 接口参数
 *  @param success    请求成功处理块
 *  @param error      请求数据错误（返回数据status_code不是100）
 *  @param failure    请求失败处理块
 */
- (void)requestWithParam:(id)parameters
                 success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                   error:(void (^)(NSInteger errorCode, NSString *errorMessage))error
                 failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
/**
 *   不带HUD
 */
- (void)requestNoHUDWithParam:(id)parameters
                      success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                        error:(void (^)(NSInteger errorCode, NSString * errorMessage))error
                      failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
/**
 *  @brief HTTP请求（默认GET方式和默认接口文件地址）
 *
 *  @param parameters 接口参数
 *  @param prepare    请求前预处理块
 *  @param success    请求成功处理块
 *  @param error      请求数据错误（返回数据status_code不是100）处理块
 *  @param failure    请求失败处理块
 */
- (void)requestWithParam:(id)parameters
          prepareExecute:(PrepareExecuteBlock) prepare
                 success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                   error:(void (^)(NSInteger errorCode, NSString *errorMessage))error
                 failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

//网络状态
@property (nonatomic, assign) BOOL isConnectionEnable;
@property (nonatomic, assign) BOOL isWifiEnable;
@property (nonatomic, assign) BOOL isWWANEnable;
@property (nonatomic, assign) BOOL connectionUnknown;
@end

